package com.yami.shop.security.api.controller;

import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 退出登陆接口
 */
@RestController
@RequestMapping("/p")
@Api(tags = "退出登陆接口")
@AllArgsConstructor
public class LogoutCntroller {
    private final ConsumerTokenServices consumerTokenServices;

    /**
     * 退出登录,并清除redis中的token
     **/
    @GetMapping("/logout")
    public Boolean removeToken(HttpServletRequest httpRequest){
        String authorization = httpRequest.getHeader("authorization");
        String token = authorization.replace("bearer", "");
        return consumerTokenServices.revokeToken(token);
    }
}
